<?php namespace Admin\Controller;
class TypeController extends CommonController{
	protected $db;
	public function __construct(){
		$this->db = new \Common\Model\Type;
		parent::__construct();
	}
	public function index(){
		$typedata = $this->db->get();
		View::with("typedata",$typedata);
		View::make();
	}
	
	//添加类型
	public function addtype(){
		
		if(IS_POST){
			
			if(!$this->db->store()){
				View::error($this->db->getError());
			}else{
				View::success("添加成功",U('Type/index'));
			}
		}
		View::make();
	}
	//编辑类型
	public function edit(){
		$type_id = intval($_GET['type_id']);
		$olddata = $this->db->where("type_id","$type_id")
		->first();
		View::with("olddata",$olddata);
		if(IS_POST){
			if(!$this->db->edit($type_id)){
				View::error($this->db->getError());
			}else{
				View::success("编辑成功",U('Type/index'));
			}
		}
		View::make();	
	}
}
